package cn.ynu.cmrs.dialog;

import cn.ynu.cmrs.R;
import cn.ynu.cmrs.MyApplication;
import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ViewFlipper;

/**
 * About dialog
 * 
 * @author Yasha
 *
 */
public class AboutDialog extends Dialog {
	
	private TextView mVersionTextView;
	private Button mDeveloperButton;
	private Button mCancelButton;
	private ViewFlipper mDeveloperViewFlipper;

	public AboutDialog(Activity context) {
		super(context);
		init(context);
	}

	public AboutDialog(Activity context, int theme) {
		super(context, theme);
		init(context);
	}

	public AboutDialog(Activity context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		init(context);
	}

	private void init(final Activity context) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.about);
		String topText = "Version " + MyApplication.getInstance().getVersion()
				+ " " + context.getString(R.string.about_note);

		mVersionTextView = (TextView) findViewById(R.id.VersionText);
		mVersionTextView.setText(topText);

		mDeveloperViewFlipper = (ViewFlipper) findViewById(R.id.AboutViewFlipper);
		mDeveloperButton = (Button) findViewById(R.id.AboutDeveloperButton);
		mDeveloperButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				int currentCompany = mDeveloperViewFlipper.getDisplayedChild();
				if (currentCompany == 0) {
					mDeveloperButton.setText(R.string.about_app);
					mDeveloperViewFlipper.setDisplayedChild(1); 
				} else {
					mDeveloperButton.setText(R.string.about_developer);
					mDeveloperViewFlipper.setDisplayedChild(0); 
				}
			}

		});

		mCancelButton = (Button) findViewById(R.id.CancelButton);
		mCancelButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				AboutDialog.this.dismiss();
			}
		});
	}
}
